import request from '@/utils/request'

// ==================== 文章管理 ====================

// 获取文章列表
export function getArticleList(params) {
  return request({
    url: '/api/zenithMind/article/list',
    method: 'get',
    params
  })
}

// 获取文章详情
export function getArticleDetail(id) {
  return request({
    url: `/api/zenithMind/article/${id}`,
    method: 'get'
  })
}

// 创建文章
export function createArticle(data) {
  return request({
    url: '/api/zenithMind/article',
    method: 'post',
    data
  })
}

// 更新文章
export function updateArticle(id, data) {
  return request({
    url: `/api/zenithMind/article/${id}`,
    method: 'put',
    data
  })
}

// 删除文章
export function deleteArticle(id) {
  return request({
    url: `/api/zenithMind/article/${id}`,
    method: 'delete'
  })
}

// 发布文章
export function publishArticle(id) {
  return request({
    url: `/api/zenithMind/article/${id}/publish`,
    method: 'post'
  })
}

// 取消发布文章
export function unpublishArticle(id) {
  return request({
    url: `/api/zenithMind/article/${id}/unpublish`,
    method: 'post'
  })
}

// 搜索文章
export function searchArticles(keyword, params) {
  return request({
    url: '/api/zenithMind/article/search',
    method: 'get',
    params: { keyword, ...params }
  })
}

// 获取热门文章
export function getHotArticles(limit = 10) {
  return request({
    url: '/api/zenithMind/article/hot',
    method: 'get',
    params: { limit }
  })
}

// 获取推荐文章
export function getRecommendArticles(limit = 10) {
  return request({
    url: '/api/zenithMind/article/recommend',
    method: 'get',
    params: { limit }
  })
}

// 获取我的文章
export function getMyArticles(params) {
  return request({
    url: '/api/zenithMind/article/my',
    method: 'get',
    params
  })
}

// 点赞文章
export function likeArticle(id) {
  return request({
    url: `/api/zenithMind/article/${id}/like`,
    method: 'post'
  })
}

// 取消点赞
export function unlikeArticle(id) {
  return request({
    url: `/api/zenithMind/article/${id}/unlike`,
    method: 'post'
  })
}

// 收藏文章
export function favoriteArticle(id) {
  return request({
    url: `/api/zenithMind/article/${id}/favorite`,
    method: 'post'
  })
}

// 取消收藏
export function unfavoriteArticle(id) {
  return request({
    url: `/api/zenithMind/article/${id}/unfavorite`,
    method: 'post'
  })
}

// 获取收藏文章
export function getFavoriteArticles(params) {
  return request({
    url: '/api/zenithMind/article/favorites',
    method: 'get',
    params
  })
}

// ==================== 文章分类管理 ====================

// 获取文章分类
export function getArticleCategories() {
  return request({
    url: '/api/zenithMind/article-category/list',
    method: 'get'
  })
}

// 获取分类树
export function getArticleCategoryTree() {
  return request({
    url: '/api/zenithMind/article-category/tree',
    method: 'get'
  })
}

// 按分类获取文章
export function getArticlesByCategory(categoryId, params) {
  return request({
    url: `/api/zenithMind/article/category/${categoryId}`,
    method: 'get',
    params
  })
}

// ==================== 文章评论管理 ====================

// 获取文章评论
export function getArticleComments(articleId, params) {
  return request({
    url: `/api/zenithMind/article/${articleId}/comments`,
    method: 'get',
    params
  })
}

// 添加评论
export function addArticleComment(articleId, data) {
  return request({
    url: `/api/zenithMind/article/${articleId}/comments`,
    method: 'post',
    data
  })
}

// 回复评论
export function replyArticleComment(commentId, data) {
  return request({
    url: `/api/zenithMind/article/comments/${commentId}/reply`,
    method: 'post',
    data
  })
}

// 删除评论
export function deleteArticleComment(commentId) {
  return request({
    url: `/api/zenithMind/article/comments/${commentId}`,
    method: 'delete'
  })
}

// 点赞评论
export function likeArticleComment(commentId) {
  return request({
    url: `/api/zenithMind/article/comments/${commentId}/like`,
    method: 'post'
  })
}

// 取消点赞评论
export function unlikeArticleComment(commentId) {
  return request({
    url: `/api/zenithMind/article/comments/${commentId}/unlike`,
    method: 'post'
  })
}

// ==================== 文章标签管理 ====================

// 获取文章标签
export function getArticleTags() {
  return request({
    url: '/api/zenithMind/article/tags',
    method: 'get'
  })
}

// 按标签获取文章
export function getArticlesByTag(tag, params) {
  return request({
    url: `/api/zenithMind/article/tag/${tag}`,
    method: 'get',
    params
  })
}

// 获取热门标签
export function getHotTags(limit = 20) {
  return request({
    url: '/api/zenithMind/article/tags/hot',
    method: 'get',
    params: { limit }
  })
}

// ==================== 文章统计 ====================

// 获取文章统计信息
export function getArticleStats(articleId) {
  return request({
    url: `/api/zenithMind/article/${articleId}/stats`,
    method: 'get'
  })
}

// 增加文章阅读量
export function increaseArticleViews(articleId) {
  return request({
    url: `/api/zenithMind/article/${articleId}/view`,
    method: 'post'
  })
}

// ==================== 文章草稿管理 ====================

// 保存文章草稿
export function saveArticleDraft(data) {
  return request({
    url: '/api/zenithMind/article/draft',
    method: 'post',
    data
  })
}

// 获取文章草稿
export function getArticleDrafts(params) {
  return request({
    url: '/api/zenithMind/article/drafts',
    method: 'get',
    params
  })
}

// 删除文章草稿
export function deleteArticleDraft(draftId) {
  return request({
    url: `/api/zenithMind/article/drafts/${draftId}`,
    method: 'delete'
  })
}

// ==================== 文章上传 ====================

// 上传文章图片
export function uploadArticleImage(formData) {
  return request({
    url: '/api/zenithMind/article/upload/image',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 上传文章附件
export function uploadArticleAttachment(formData) {
  return request({
    url: '/api/zenithMind/article/upload/attachment',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
